<?php

namespace App\Http\Controllers\Common;

use App\Helpers\ResponseData;
use App\Http\Controllers\Controller;
use App\Models\VisitRecord;
use Illuminate\Http\Request;
//用户访问记录
class VisitRecordController extends Controller
{

    use ResponseData;
    public function index(VisitRecord $model,Request $request){
        if($request->filled('department_id')){
            $model = $model->where('department_id',$request->department_id);
        }
        $size = $request->input('size',10);
        $model = $model->orderBy('id','desc')->paginate($size);
        return $this->success($model);
    }
    // 访问记录
    public function inter(Request $request,VisitRecord $record){
        $data = $record->create($request->all());
        $val['id'] = $data->id;
        $val['message'] = '添加成功';
        return $this->success($val);
    }
    public function leave(Request $request,VisitRecord $record){
        $model = $record->find($request->id);
        if($model){
            $model->update(['updated_at'=>now()]);
        }

        return $this->success('更新成功');
    }
}
